import cv2

img=cv2.imread(r'C:\Users\ASUS\Desktop\4.JPG') #读取图片
Average=cv2.blur(img,(3,3),0) #均值滤波
Gauss=cv2.GaussianBlur(img,(3,3),0) #高斯滤波
Median=cv2.medianBlur(img,3) #中值滤波
kernel=cv2.getStructuringElement(cv2.MORPH_RECT,(5,5)) #定义结构元素
opened=cv2.morphologyEx(img,cv2.MORPH_OPEN,kernel)
closed=cv2.morphologyEx(opened,cv2.MORPH_CLOSE,kernel) #先开后闭运算

cv2.imshow('A',Average)
cv2.imshow('G',Gauss)
cv2.imshow('M',Median)
cv2.imshow('C2O',closed)

cv2.waitKey()
cv2.destroyAllWindows()